package org.fzu.ercha.wuta.Util;

import android.util.Log;

/**
 * Created by ercha on 2016/10/18.
 */

public class LogUtil {
    private static final String PACKGE_NAME = "org.fzu.ercha.wuta";
    private static final int VERBOSE = 1;
    private static final int DEBUG = 2;
    private static final int INFO = 3;
    private static final int WARN = 4;
    private static final int ERROR = 5;
    private static final int NOTHING = 6;
    private static final int LEVEL = VERBOSE;

    public static void v(String tag, String msg) {
        if (LEVEL <= VERBOSE) {
            Log.v(PACKGE_NAME + "   " + tag, msg);
        }
    }
    public static void d(String tag, String msg) {
        if (LEVEL <= DEBUG) {
            Log.d(PACKGE_NAME + "   " + tag, msg);
        }
    }
    public static void i(String tag, String msg) {
        if (LEVEL <= INFO) {
            Log.i(PACKGE_NAME + "   " + tag, msg);
        }
    }

    public static void w(String tag, String msg) {
        if (LEVEL <= WARN) {
            Log.w(PACKGE_NAME + "   " + tag, msg);
        }
    }

    public static void e(String tag, String msg) {
        if (LEVEL <= ERROR) {
            Log.e(PACKGE_NAME + "   " + tag, msg);
        }
    }

    public static void e(String msg){
        if (LEVEL <= ERROR) {
            String fullClassName = Thread.currentThread().getStackTrace()[3].getClassName();
            String className = fullClassName.substring(fullClassName.lastIndexOf(".") + 1);
            String methodName = Thread.currentThread().getStackTrace()[3].getMethodName();
            int lineNumber = Thread.currentThread().getStackTrace()[3].getLineNumber();

            Log.e("error in " + className + "." + methodName + ", line " + lineNumber, msg);
        }
    }

    /**
     * 打印的类信息是调用者的调用者类
     * @param msg
     */
    public static void ge(String msg){
        if (LEVEL <= ERROR) {
            String fullClassName = Thread.currentThread().getStackTrace()[4].getClassName();
            String className = fullClassName.substring(fullClassName.lastIndexOf(".") + 1);
            String methodName = Thread.currentThread().getStackTrace()[4].getMethodName();
            int lineNumber = Thread.currentThread().getStackTrace()[4].getLineNumber();

            Log.e("error in " + className + "." + methodName + ", line " + lineNumber, msg);
        }
    }
}
